package com.lagou.work.workone;

public class ProgramTest {

    public static void main(String[] args) {
        //声明二维数组
        int[][] numArray = new int[16][16];
        //对数组进行统一赋值,将每一行的值按当前行的数组下标进行赋值
        for (int i = 0; i < numArray.length; i++) {
            for (int j = 0; j < numArray[i].length; j++){
                numArray[i][j] = i + j;
                System.out.print(numArray[i][j] + " ");
            }
            System.out.println();
        }
        //实现每一行的数据求和
        for (int i = 0; i < numArray.length; i++) {
            int rowSum = 0;
            for (int j = 0; j < numArray[i].length; j++){
                rowSum += numArray[i][j];
            }
            System.out.println("第" + (i + 1) +"行的和为" + rowSum);
        }
        System.out.println("------------------------------------");
        //实现每一列的数据求和
        int colLength = numArray[0].length;
        for (int i=0;i<colLength;i++){
            int colSum = 0;
            for (int j=0;j< numArray.length;j++){
                colSum += numArray[j][i];
            }
            System.out.println("第" + (i + 1) +"列的和为" + colSum);
        }
        System.out.println("------------------------------------");
        //实现左上角到右下角加和
        int sum = 0;
        for (int i = 0; i < numArray.length; i++) {
            sum += numArray[i][i];
        }
        System.out.println("左上角到右下角的和为" + sum);
        System.out.println("------------------------------------");
        //实现右上角到左下角加和
        int sum1 = 0;
        int midColLen = colLength - 1;
        for (int i = 0; i < numArray.length; i++) {
            int yInd = midColLen--;
            sum1 += numArray[i][yInd];
        }
        System.out.println("右上角到左下角的和为" + sum1);
    }
}
